import {fetchList} from '@/services/user/UserOrderPolypay';

export default {
  namespace: 'POrderPolypay',

  state: {
    dataTable: {
      total: 0,
      list: [],
    },
  },

  effects: {
    * fetchList({payload}, {call, put}) {
      const response = yield call(fetchList, payload);
      if (response.code === 0) {
        let dataTable = response.data;
        dataTable.list = dataTable.list.map(d => {
          d.mchName = d.mchInfo ? d.mchInfo.name : null;
          return d;
        });
        yield put({
          type: 'chgDataTable',
          payload: dataTable,
        });
      }
    },
  },

  reducers: {
    chgDataTable(state, action) {
      return {
        ...state,
        dataTable: action.payload,
      };
    },
  },
};
